from core import myapp
from bson.dbref import DBRef
from db.mongodb import DBConn

app = myapp


class TestData():
    conn = DBConn()
    db = conn.get_database('shawe')
    
    # The following are existing data imported
    user = db.find_one('users', 
                       {'username':'zlk', 
                       'password':'zlk',
                       'email':'likzhang@gmail.com', 
                       'role':'0', #0 admin, 1 user
                       'phone': '519-334-6720',
                       'description':"I'm IT man"})
    if user is not None:
        user_ref = DBRef('users', user['_id'])
    
    city = db.find_one('cities',{'city':'London', 'province':'ON'})
    city_ref = DBRef('cities', city['_id'])
    
    address = db.find_one('addresses',{'unit':'0', 
                   'street_no':'1536',
                   'street_name':'Foxcreek Rd', 
                   'postcode':'N6G0C9',
                   'city': city_ref})
    address_ref = DBRef('addresses', address['_id'])
    
    house = db.find_one('houses', 
            {'name':'my house',
               'description':'my house description',
               'year': '2003',
               'price':'230000', 
               'status':'0', 
               'style':'1', 
               'n_rooms':'3', 
               'n_baths':'3', 
               'n_garages':'2',
               'basement':'1',
               'lots':'40',
               'living_space':'3000',
               'faces':'0', 
               'deck':'1',
               'patio':'0',
               'fence':'1',
               'ac':'1',
               'address':address_ref})
    if house is not None:
        house_ref = DBRef('houses', house['_id'])

    category = db.find_one('categories', {'name':'house'})
    category_ref = DBRef('categories', category['_id'])

    advertisement = db.find_one('advertisements',
                    { 'prefer_contact':0,#0 email, 1 phone
                       'email':'likzhang@gmail.com',
                       'phone': '519-572-0859',
                       'type':0, # 0 rent, 1 sell
                       'category':category_ref,
                       'item':house_ref,
                       'user':user_ref})
    
    if advertisement is not None:
        advertisement_ref = DBRef('advertisements', advertisement['_id'])
    
    
    picture = db.find_one('pictures',{'name':'my house picture',
               'description':'my house outside',
               'fname': r'my.jpg',
               'order':0, # 0 rent, 1 sell
               'category':category_ref,
               'item':house_ref})
    
    if picture is not None:
        picture_ref = DBRef('pictures', picture['_id'])
       
    
test_data = TestData() 